package net;


import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.SocketAddress;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
  
public class ClientSystem {  
      
    public Object sentNetCmd(NetCommand cmd) throws Exception { 
        	Object receive = null;
            Socket socket = null;  
            GZIPOutputStream gzipos = null;
            ObjectOutputStream oos = null;
            GZIPInputStream gzipis = null;
            ObjectInputStream ois = null;
              
            try {
                socket = new Socket();  
                SocketAddress socketAddress = new InetSocketAddress("localhost", 10000);   
                socket.connect(socketAddress, 10 * 1000);  
                socket.setSoTimeout(10 * 1000);  
                  
                gzipos = new GZIPOutputStream(socket.getOutputStream());  
                oos = new ObjectOutputStream(gzipos);  
                oos.writeObject(cmd);  
                oos.flush();
                gzipos.finish();
                  
                gzipis = new GZIPInputStream(socket.getInputStream());  
                ois = new ObjectInputStream(gzipis);  
                Object obj = ois.readObject();  
                if (obj != null) {  
                	receive = obj;
                }
                return receive;
            } catch(IOException ex) {  
            	System.err.println("Internet IO Error!");
            } finally {  
                try {  
                    ois.close();  
                } catch(Exception ex) {}  
                try {  
                    oos.close();  
                } catch(Exception ex) {}  
                try {  
                    socket.close();  
                } catch(Exception ex) {}  
            }  
		return receive;  
    }  
}  